[Logger] Support log4j-2.20+#471
Open
DriverSong wants to merge 1 commit intoray-project:masterfrom
Open
Conversation
slfan1989
approved these changes
May 10, 2026
There was a problem hiding this comment.
Pull request overview
Updates the SLF4J binding initialization in RayDP’s agent to remain compatible with Log4j 2.20+, which removed the no-arg constructor from org.apache.logging.slf4j.Log4jLoggerFactory.
Changes:
- Adds a reflective fallback path to instantiate
Log4jLoggerFactoryusing theLog4jLoggerFactory(LoggerContext)constructor when no no-arg constructor is available. - Introduces reflection imports and logic to obtain a
LoggerContextviaLogManager.getContext(false).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
103
to
+112
| try { | ||
| tmpFactory = (ILoggerFactory) tempClass.newInstance(); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| // log4j 2.20+ removed the no-arg constructor from | ||
| // Log4jLoggerFactory. Fall back to the constructor that | ||
| // accepts a LoggerContext. | ||
| try { | ||
| Class<?> ctxClass = Class.forName( | ||
| "org.apache.logging.log4j.spi.LoggerContext"); | ||
| Constructor<?> ctor = tempClass.getConstructor(ctxClass); |
| .invoke(null, false); | ||
| tmpFactory = (ILoggerFactory) ctor.newInstance(ctx); | ||
| } catch (Exception ex) { | ||
| e.printStackTrace(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While log4j 2.20+ remove no-arg constructor from Log4jLoggerFactory and ray-2.54.0 use log4j 2.25.3, raydp should support the new constructor
Log4jLoggerFactory(LoggerContext).